
$(document).ready(function(){
    $("#NewsForm_title").change(function(){
		var param  = script.init(/taglist.js/g,'%').param; //解析参数；
		var newtitle = $(this).val();
		var layout = '<style>'
					+'#art_dialog_layout{width:600px;height:400px;}'
					+'#art_dialog_layout table tr td{margin:0 ;padding:0;border:1px solid #999;text-align:center;}'
					+'#art_dialog_layout table tr{height:30px;}'
					+'#art_dialog_layout .searchbox{width:590px;height:40px;background:#ddd;}'
					+'#art_dialog_layout .searchbox input{lineHeight:40px;height:25px;}'
					+'#art_dialog_layout .searchbox .text{width:220px; height:22px;margin-top:8px; margin-left:20px;}'
					+'#art_dialog_layout .searchbox .button{width:60px;text-align:center; height:25px;margin-top:8px;}'
					+'</style>'
					+'<div id="art_dialog_layout" ><table>{content}</table></div>';
					
		//公共前端选软方法；
		var render = function(str,arrx){
			var param,name ;
			param = str.match(/{([0-9a-zA-Z_]+)}/g);
			if(!param) return str ;
			for(var v in param){
				name = param[v].substr(1,(param[v].length-2));
				if(arrx[name]){
					str = str.replace(param[v],arrx[name]);
				}else{
					str = str.replace(param[v],'');
				}
			}
			return str ;
		};
		


        var arrx = {content:''} ;
        var api = '/admin/article/gl/AjaxIsLikeTitle2';
        var rand = Math.random();
        $.getJSON(api,{rand:rand,title:newtitle},function(data){
            if(data.status==300){
                console.log('没有匹配的文章');
            }else{
                art.dialog({
                    id:'taglist',
                    title:'相似标题文章',
                    width:'600px',
                    height:'400px',
                    content:'请稍后……'
                });
                showlist(data);
			}

        });
		

		
		//数据拼接；
		var showlist = function(data){
			if(data.status==400){
				alert('请输入文章名');
			}else if(data.status==300){
				alert('没有匹配的文章');
			}else if(data.status==200){
				arrx.label = '搜索匹配文章成功，匹配的文章.';
				arrx.content = '<tr><td width="80">id</td><td width="520" >文章名</td></tr>';
				for(var v in data.data){
					arrx.content += '<tr><td>'+data.data[v].id+'</td><td><a href="https://www.fam365.com/gonglue/'+data.data[v].id+'.html" target="_blank">'+data.data[v].title+'</a></td></tr>';
				}
			}
			var content = render(layout,arrx);
			art.dialog.list['taglist'].content(content);
		}
		
	});
});